<template>
  <group title="用户信息" class="change">
    <x-input title="手&emsp;&emsp;机：" v-model="userInfo.mobile" readonly></x-input>
    <x-input title="代理昵称：" v-model="nickname" :show-clear="false"></x-input>
    <x-input title="微&emsp;&emsp;信：" v-model="wxnumber" :show-clear="false"></x-input>
    <popup-picker title="游&emsp;&emsp;戏：" :data="gameList" v-model="game" show-name></popup-picker>
    <popup-picker title="所属城市：" :data="cities" v-model="city" show-name></popup-picker>
    <popup-picker title="所属区县：" :data="counties" v-model="county" show-name></popup-picker>
    <x-input title="代理等级：" v-model="agentLevel" :show-clear="false"></x-input>
    <cell title="冻结用户">
      <check-icon :value.sync="lock">是</check-icon>
      <check-icon :value.sync="unlock">否</check-icon>
    </cell>
    <!-- <p>{{[county[0]]}}</p> -->
    <x-input title="备&emsp;&emsp;注：" v-model="remarks"></x-input>
    <agent-button @btnClick="saveClick">保存</agent-button>
  </group>
</template>
<script>
import { Group, XInput, PopupPicker, CheckIcon, Cell } from "vux";
import AgentButton from "../../../components/common/AgentButton.vue";
import { userInfo } from "os";
export default {
  data() {
    return {
      userInfo: [],
      gameList: [],
      cities: [],
      counties: [],
      county: [],
      city: ["1"],
      game: ["1"],
      lock: true,
      nickname: JSON.parse(this.$route.query.userInfo).nickname,
      wxnumber: JSON.parse(this.$route.query.userInfo).wxnumber,
      remarks: ""
    };
  },
  components: {
    Group,
    XInput,
    PopupPicker,
    AgentButton,
    CheckIcon,
    Cell
  },
  computed: {
    unlock: {
      get() {
        return !this.lock;
      },
      set() {
        this.lock = !this.lock;
      }
    },
    agentLevel: {
      get() {
        if (this.userInfo.level == 2) {
          return "二级代理";
        }
        if (this.userInfo.level == 1) {
          return "一级代理";
        }
        if (this.userInfo.level == 0) {
          return "总代";
        }
      },
      set() {}
    }
  },
  watch: {
    city() {
      this.fetchCounties(this.city[0]);
    }
  },
  created() {
    this.userInfo = JSON.parse(this.$route.query.userInfo);
    this.$set(this.city, 0, this.userInfo.regionid.toString());
    this.$set(this.game, 0, this.userInfo.gameid.toString());
    this.$set(this.county, 0, this.userInfo.county.toString());
    this.apiService.user.getgamelist().then(res => {
      let lists = res.data.gamelist.map(item => {
        return {
          name: item.name,
          value: item.id
        };
      });
      this.$set(this.gameList, 0, lists);
    });
    this.apiService.user.getregion().then(res => {
      let lists = res.data.regionlist.map(item => {
        return {
          name: item.name,
          value: item.id
        };
      });
      this.$set(this.cities, 0, lists);
    });
    this.fetchCounties(this.userInfo.county);
  },
  methods: {
    saveClick() {
      this.apiService.agent
        .modifyagent({
          agentid: this.userInfo.user_id,
          nickname: this.nickname,
          wxnumber: this.wxnumber,
          regionid: this.city[0],
          gameid: this.game[0],
          county: this.county[0],
          area: "",
          remarks: this.remarks,
          islock: this.lock ? "1" : "2"
        })
        .then(res => {
          this.$vux.toast.text("保存成功");
          this.$router.go(-1);
        });
    },
    fetchCounties(city = 1) {
      return this.apiService.user
        .getsecondregion({
          parentid: city
        })
        .then(res => {
          let lists = res.data.regionlist.map(item => {
            return {
              name: item.name,
              value: item.id
            };
          });
          this.$set(this.counties, 0, lists);
        });
    }
  }
};
</script>

<style>
.change input {
  color: var(--word-gray-color);
  text-align: right;
}
</style>


